package com.example.exercises._002_简单排序;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class XianShi {


    public static void main(String[] args) {

        String[] name = {"丁一", "钱二", "张三", "李四", "王五", "赵六",};
        String[] sex = {"男", "男", "男", "男", "女", "女"};
        int[] score = {68, 76, 73, 86, 73, 96};

        System.out.println("姓名\t性别\t成绩");

        for (int i = 0; i < name.length; i++) {
            System.out.println(name[i] + "\t" + sex[i] + "\t" + score[i]);
        }
        //
        //
        //
        System.out.println("\n\n第二题开始");
        ArrayList<People> people = new ArrayList<>();
        for (int i = 0; i < name.length; i++) {
            people.add(new People(name[i], sex[i], score[i]));
        }
        //排序
        Collections.sort(people, new Comparator<People>() {
            @Override
            public int compare(People o1, People o2) {

                // 升序
                //return o1.getAge()-o2.getAge();
                //return o1.getAge().compareTo(o2.getAge());

                // 降序
                // return o2.getAge()-o1.getAge();
                // return o2.getAge().compareTo(o1.getAge());

                return o2.score - o1.score;
            }
        });

        System.out.println("姓名\t性别\t成绩");
        for (int i = 0; i < people.size(); i++) {
            System.out.println(people.get(i).name + "\t" + people.get(i).sex + "\t" + people.get(i).score);
        }

    }

    static class People {
        public String name;
        public String sex;
        public int score;

        public People(String name, String sex, int score) {
            this.name = name;
            this.sex = sex;
            this.score = score;
        }
    }
}
